<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<title>Insert title here</title>
<link href="static/easyui/themes/default/easyui.css" rel="stylesheet" />
<link href="static/easyui/themes/icon.css" rel="stylesheet" />
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui-lang-zh_CN.js"></script>
</head>
<body>
	<% String username = String.valueOf(session.getAttribute("username")); %>
	<form id="editPasswordForm">
		<table>
			<tr>
				<td>当前密码：</td>
				<td><input class="easyui-passwordbox" type="password"
							id="password" name="password" data-options=""></input>
				</td>
			</tr>
			<tr>
				<td>新密码：</td>
				<td><input class="easyui-passwordbox" type="password"
							id="newPassword" name="newPassword" data-options=""></input></td>
			</tr>
			<tr>
				<td>确认密码：</td>
				<td>
					<input class="easyui-passwordbox" type="password"
							id="checkPassword" name="checkPassword" data-options=""></input>
				</td>
			</tr>
			
			
			<tr>
				<td><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="submit()" >提交</a></td>
				<td><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="reset()" >重置</a></td>
			</tr>
		</table>
	</form>
	<script>
		$(function(){
			
		});
		function submit() {
			var password = $("#password").val();
			var newPassword = $("#newPassword").val();
			var checkPassword = $("#checkPassword").val();
			if (!isNotBlank(password) || !isNotBlank(newPassword) || !isNotBlank(checkPassword)) {
				$.messager.alert('提示', '请输入完整！', 'error');
				return;
			}
			if(!isSame(newPassword, checkPassword)) {
				$.messager.alert('提示', '两次密码不一致！', 'error');
				return;
			}
			
			$.ajax({
				type: "post",
				url: "editPassword.do",
				data: {
					"username": "<%=username%>",
					"password": password,
					"newPassword": newPassword
				},
				success: function(response) {
					if(response.code == 0) {
						$.messager.alert('提示', response.message+",请重新登录！", 'info');
						parent.location.href = "login.jsp";
					} else {
						$.messager.alert('提示', response.message + 'info');
					}
				}
			})
		}
		function reset() {
			$("#newPassword").passwordbox("clear");
			$("#checkPassword").passwordbox("clear");
		}
		
		function isNotBlank(password) {
			if (password == '' || password == null) {
				return false;
			}
			return true;
		}
		
		// 校验两次密码是否一致
		function isSame(password1, password2) {
			if (password1 != password2) {
				return false;
			}
			return true;
		}
	</script>
</body>
</html>